import Vue from 'vue'
import Router from 'vue-router'
import layout from '@/layout/index'
import store from '@/store'

Vue.use(Router)
const router = new Router({
    routes: [
        {
            path: '/login',
            name: 'login',
            component: () => import('@/views/login')
        },
        {
            path: '/',
            redirect: '/login',
            component: () => import('@/views/login')
        },
        {
            path: '/home',
            component: layout
        },
        {
            path: '/main',
            component: layout,
            children: [
                {
                    path: '/funcHall',
                    component: () => import('@/views/FuncHall.vue')
                },
                {
                    path: '/paperPractice',
                    component: () => import('@/views/PaperPractice.vue')
                },
                {
                    path: '/paperExam',
                    component: () => import('@/views/PaperExam.vue')
                },
                {
                    path: '/paperBank',
                    component: () => import('@/views/PaperBank.vue')
                },
                {
                    path: '/bankManager',
                    component: () => import('@/views/PaperBankManager.vue')
                },
                {
                    path: '/paperDetails',
                    component: () => import('@/views/PaperDetails.vue')
                },
                {
                    path: '/paperCenter',
                    component: () => import('@/views/PaperCenter.vue')
                },
                {
                    path: '/paperTemplate',
                    component: () => import('@/views/PaperTemplateMan.vue')
                },
                {
                    path: '/problemDetail',
                    component: () => import('@/views/ProblemDetail.vue')
                },
                {
                    path: '/watchVideo',
                    component: () => import('@/views/WatchVideo.vue')
                },
                {
                    path: '/watchLog',
                    component: () => import('@/views/WatchLog.vue')
                },
                {
                    path: '/videoMan',
                    component: () => import('@/views/VideoMan.vue')
                },
                {
                    path: '/allVideo',
                    component: () => import('@/views/AllVideo.vue')
                },
                {
                    path: '/videoDetail',
                    component: () => import('@/views/VideoDetails.vue')
                },
                {
                    path: '/deptMan',
                    component: () => import('@/views/DeptMan.vue')
                },
                {
                    path: '/selfDept',
                    component: () => import('@/views/SelfDept.vue')
                },
                {
                    path: '/authMan',
                    component: () => import('@/views/AuthMan.vue')
                },
                {
                    path: '/positionMan',
                    component: () => import('@/views/PositionMan.vue')
                },
                {
                    path: '/personCenter',
                    component: () => import('@/views/PersonCenter.vue')
                },
                {
                    path: '/approvalMan',
                    component: () => import('@/views/ApprovalMan.vue')
                },
                {
                    path: '/applyMan',
                    component: () => import('@/views/ApplyMan.vue')
                }
            ]
        }
    ]
})
// 路由导航守卫
// 权限验证：判断当前请求是否能够访问
// 动态路由
router.beforeEach((to, from, next) => {
    // to：来源地址，from：跳转地址，next：放行函数next()-直接放行，next('/path')放行并跳转到指定路径
    store.state.routerData
    next()
})

export default router